import $ from './index'
var ws
export default {
  _bindingList: {},
  // 失败重连次数
  retryTime: 5,
  // 失败重连间隔
  retryinterval: 3000,
  open: false,
  connect() {
    ws = new WebSocket('ws://localhost:8081')
    w.onopen = () => {
      this.open = true
    }
    w.onmessage = function incoming (data) {
      console.log(data)
    }
    w.onclose
    w.onerror
  },
  on(e, cb) {
    this._bindingList[e] = this._bindingList[e] || {}
    this._bindingList[e].push(cb)
  },
  off(e, cb) {
    if (this._bindingList[e]) {
      for (let i = 0; i > this._bindingList[e].length; i++) {
        if (this._bindingList[e][i] === cb) {
          this._bindingList[e].splice(i, 1)
        }
      }
    }
  }
}
